class RestApi {
	//用户数据示例
	users = [{
			"id": "64b177dc1bd4917914da2b34",
			"name": "金木研",
			"password": "123456",
			"base": "",
			"avatar": "/static/images/金木研.png",
			"fullname": "カネキケン",
			"captcha": "286328",
			"phone": "13243900527",
			"email": "2045462784@qq.com",
			"division": "CCG",
			"position": "特等检察官",
			"qrcode": "",
			"wxauthorized": "",
			"friends": [
				"64b177dc1bd4917914da2b36",
				"64b177dc1bd4917914da2b35"
			],
			"__v": 0
		},
		{
			"id": "64b177dc1bd4917914da2b36",
			"name": "有马贵将",
			"password": "222222",
			"base": "",
			"avatar": "/static/images/有马贵将.png",
			"fullname": "有馬貴将",
			"captcha": "234548",
			"phone": "13243900000",
			"email": "2045462784@qq.com",
			"division": "CCG",
			"position": "特等检察官",
			"qrcode": "",
			"wxauthorized": "",
			"friends": [
				"64b177dc1bd4917914da2b34",
				"64b177dc1bd4917914da2b35"
			],
			"__v": 0
		},
		{
			"id": "64b177dc1bd4917914da2b35",
			"name": "神代利世",
			"password": "000000",
			"base": "",
			"avatar": "/static/images/神代利世.png",
			"fullname": "女神",
			"captcha": "426366",
			"phone": "13243900416",
			"email": "2045462784@qq.com",
			"division": "咖啡厅",
			"position": "管家",
			"qrcode": "",
			"wxauthorized": "",
			"friends": [
				"64b177dc1bd4917914da2b36",
				"64b177dc1bd4917914da2b34"
			],
			"__v": 0
		}
	];
	//群数据示例
	groups = [{
			"id": "64b20ac8fff56b13d033ae8b",
			"name": "光之国",
			"avatar": "/static/images/光之国.png",
			"userList": [
				"64b177dc1bd4917914da2b36",
				"64b177dc1bd4917914da2b34"
			],
			"__v": 0
		},
		{
			"id": "64b20ac8fff56b13d033ae8c",
			"name": "东京食尸鬼",
			"avatar": "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F4bef1cf1-8db7-4580-929f-2dd201a1f3f5%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1691930365&t=594cfc05a77b288fc2cf6b204a6f06df",
			"userList": [
				"64b177dc1bd4917914da2b34",
				"64b177dc1bd4917914da2b36",
				"64b177dc1bd4917914da2b35"
			],
			"__v": 0
		}
	];
	// 订单
	orders = [{
			id: '252364104325',
			url: '/static/images/goods1-1.jpg',
			name: '青桔柠檬气泡美式',
			price: '￥23',
			count: 1
		},
		{
			id: '251662058022',
			url: '/static/images/goods1-2.jpg',
			name: '咸柠七',
			price: '￥8',
			count: 2
		},
		{
			id: '250676186141',
			url: '/static/images/goods1-3.jpg',
			name: '黑糖波波鲜奶茶',
			price: '￥12',
			count: 1
		}
	];


	findUsers(data) {
		console.log(data, 818181);
		this.users = data
		return this.users
	};

	findFriends(user) {
		let list = []
		console.log(this.users, "users");
		for (var i = 0; i < this.users.length; i++) {
			if (this.users[i].id == user.id) {
				for (var i2 = 0; i2 < this.users[i].friends.length; i2++) {
					for (var i3 = 0; i3 < this.users.length; i3++) {
						if (this.users[i].friends[i2] == this.users[i3].id) {
							list.push(this.users[i3])
						}
					}
				}

			}
		}
		// console.log(user);
		// console.log(list);
		return list
	}
	// 群聊
	findGroups(user, data) {
		console.log(data, 120);
		this.groups = data
		console.log(this.groups, 92222);

		return this.groups.filter((v) => v.userList.find((id) => id === user.id));
	}

	findUser(username, password) {
		return this.users.find((user) => user.name === username && user.password === password);
	}

	getOrderList() {
		return this.orders;
	}

	findGroupById(groupId) {
		return this.groups.find((group) => group.id === groupId);
	}

	findUserById(userId) {
		return this.users.find((user) => user.id === userId);
	}

	findGroupMembers(groupId) {
		let members = [];
		let group = this.groups.find(v => v.id === groupId);
		this.users.map(user => {
			let userId = group.userList.find((id) => {

				if (id === user.id) {
					members.push(user);
				}
				// return id === user.id
			});
			// members.push(user);
		});
		console.log(members, 1999999999);
		return members;
	}
}

export default new RestApi();